﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using _8_20_Homework.Models;

namespace _8_20_Homework.Controllers
{
    public class HomeController : Controller
    {
        List<Student> students = new List<Student>()
        {
            new Student("John Smith", Grade.Third,"Mrs. Doubtfire","http://icons.iconarchive.com/icons/visualpharm/must-have/256/User-icon.png",0),
            new Student("Jackie Chan", Grade.Third,"Mrs. Doubtfire","http://www.almazovcentre.ru/wp-content/uploads/patient.png",1),
            new Student("Jane Hopkins", Grade.Fourth,"Mrs. Doubtfire","https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcRiqTGd9rcFZm0enmJjavjP0J2Odu0UIEWeS4jI55hG2Dz_GFJc",2),
            new Student("Billy Ripken", Grade.Fourth,"Mrs. Doubtfire","https://gp3.googleusercontent.com/-kIUNFqxq8gY/AAAAAAAAAAI/AAAAAAAAFAY/NjaPlHa-V0g/s48-c-k-no/photo.jpg",3),
            new Student("Jerrod Garbett", Grade.Second,"Mrs. Doubtfire","http://paramed.bpums.ac.ir/UploadedFiles/xfiles/Image/D-pirapezeshki/icon/fc9fc83c.png",4),
            new Student("Luci Vermillion", Grade.Second,"Mrs. Doubtfire","http://genie-procedes.u-3mrs.fr/img/user-icon-female-white-hi.png",5),
            new Student("Drew Hofstetter", Grade.Fourth,"Mr. Blackston","http://thumbs.dreamstime.com/z/user-icon-9233164.jpg",6),
            new Student("Joanne Pennock", Grade.Fifth,"Mr. Blackston","http://img2.stockfresh.com/files/k/kraska/m/60/808336_95628963.jpg",7),
            new Student("Katie Clary", Grade.Fifth,"Mr. Blackston","http://www.customcontrols.co.nz/Company/ContactUs/Images/user-female-icon.png",8),
            new Student("Lois Lane", Grade.Sixth,"Mr. Blackston","https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQycyAfp2wn_O7NV0HAkiJWXhherffcGbHrvggRiESxgEdV2dXW",9),
            new Student("Clark Kent", Grade.Sixth, "Mr. Blackston", "http://thumbs.dreamstime.com/x/vector-user-icon-7337510.jpg",10)
        };
        public ActionResult Index()
        {
            return View();
        }

        [HttpGet]
        public ActionResult Add()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Add(string name, Grade grade, string teacher, string image)
        {
            Student s = new Student();
            s.Name = name;
            s.Grade = grade;
            s.Teacher = teacher;
            s.Image = image;
            students.Add(s);
            return RedirectToAction("List");
        }

        [HttpPost]
        public ActionResult Edit()
        {
            return View();
        }
        [HttpGet]
        public ActionResult Edit(string name, Grade grade, string teacher, string image)
        {
            Student s = new Student();
            s.Name = name;
            s.Grade = grade;
            s.Teacher = teacher;
            s.Image = image;
            students.Add(s);
            return RedirectToAction("Detail",s.ID);
        }
        public ActionResult List()
        {
            return View(students);
        }
        public ActionResult Detail(int id)
        {
            Student stu = new Student();
            stu = students.Where(x => x.ID == id).FirstOrDefault();
            return View(stu);
        }
        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }
    }
}